﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Bussiness.Interfaces;
using Truextend.CoffeShop.Model;
using Truextend.Common.Data;

namespace Truextend.CoffeShop.Bussiness
{
    public class ProductManager: Repository<Product>, IProductManager
    {        

        public ProductManager(IUnitOfWork unitOfWork) : base(unitOfWork)
        {            

        }

        public IList<Product> GetAllInternalProducts()
        {
            var context = (CoffeShopEntities)Context;
            if (context != null)
            {
                var info = from p in context.Product where p.Restaurant.Name == "Truextend" select p;
                return info.ToList();
            }
            return new List<Product>();

            
        }

        public IList<Product> GetAllProductsForRestaurant(int restaurantId)
        {
            var context = (CoffeShopEntities)Context;

            var info = from p in context.Product where p.Restaurant.RestaurantId == restaurantId select p;

            return info.ToList();
        }

        public Product GetProductById(int productId)
        {
            var context = (CoffeShopEntities)Context;            
            
            var info = from p in context.Product where p.ProductId == productId select p;
            
            return info.First();
        }
    }
}
